<?php
if (!defined('IN_RJ_ADMIN')) die("Error 404");

if ($level != 1) {
	echo $lang_acp['u_not_enter'];
	exit();
}
if ($mode == 'change') {

}
else {
	if (!$_POST['submit']) {
	?>

	<form method="post">
	<table cellspacing="0" width="90%" class=border>
		<tr><td colspan=2 align=center class=title><b>Config Sever Media</b></td></tr>

		<tr><td class=fr><?=$lang_acp['number_server']?> :</td><td class=fr_2><input name="s_total_server" size="15" value="<?=$conf['total_server']?>"></td></tr>
		<?

		preg_match_all("#<server>(.*?)</server>#",$conf['data_server'],$r);
		if(count($r[0])>0){
				for($i=0;$i<count($r[0]);$i++){
				$j=$i+1;
				preg_match("#<id>([0-9]+)</id>#",$r[1][$i],$match);
				preg_match("#<folder>(.*?)</folder>#",$r[1][$i],$match1);
				preg_match("#<host>(.*?)</host>#",$r[1][$i],$match2);
		?>
		
		<tr><td class=fr><?=$lang_acp['media_folder']?> <?=$match[1]?> :</td><td class=fr_2><input name="s_folder[<?=$j?>]" size="32" value="<?=$match1[1]?>"></td></tr>
		<tr><td class=fr><?=$lang_acp['link_media_host']?> <?=$match[1]?> :</td><td class=fr_2><input name="s_url[<?=$j?>]" size="50" value="<?=$match2[1]?>"></td></tr>
		
		<?
				}
		}		
		else{
				for($i=1;$i<=$conf['total_server'];$i++){
	
		?>
		
		<tr><td class=fr><?=$lang_acp['media_folder']?> <?=$i?> :</td><td class=fr_2><input name="s_folder[<?=$i?>]" size="32" value=""></td></tr>
		<tr><td class=fr><?=$lang_acp['link_media_host']?> <?=$i?> :</td><td class=fr_2><input name="s_url[<?=$i?>]" size="50" value=""></td></tr>
		
		<?
				}
		}
		?>

		<tr><td colspan="2" align="center" class=fr><input type="submit" value="<?=$lang_acp['edit']?>" name=submit class=submit></td></tr>
		<tr><td colspan=2>
		<?=$lang_acp['server_desc_1']?> : http://(<?=$lang_acp['link_media_host']?>)/(<?=$lang_acp['media_folder']?>)/link_media.mp3<br>
		<?=$lang_acp['server_desc_2']?><br>
		<?=$lang_acp['example']?> : <b>http://yourdomain.com/data/link_media.mp3</b>
		</td></tr>
	</td></tr>
	</table>
	</form>
	<?php
	}
	else {
	$xml='';
		$s_total_server=(int)$_POST['s_total_server'];
			for($i=1;$i<=$s_total_server;$i++){
				$s_folder=$_POST['s_folder'][$i];
				$s_url=$_POST['s_url'][$i];
				$xml.="<server><id>{$i}</id><folder>{$s_folder}</folder><host>{$s_url}</host></server>\n";
			}
			$DB->query("UPDATE ".$conf['prefix']."config SET config_value = '".$xml."' WHERE config_name = 'data_server'");
			$DB->query("UPDATE ".$conf['prefix']."config SET config_value = '".$s_total_server."' WHERE config_name = 'total_server'");
			
		echo $lang_acp['edited']." <meta http-equiv='refresh' content='1;url=$link'>";
	}
}
?>